﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BUS;
using DTO;
using System.IO;

namespace CungMuaC5.Account_Admin
{
    public partial class KM_Sua : System.Web.UI.Page
    {
        int MaKM;
        protected void Page_Load(object sender, EventArgs e)
        {
            MaKM = int.Parse(Request.QueryString["ma"].ToString());
            
            LoadTinKM();

        }
        int makm;
        public void LoadTinKM()
        {
            BUS_KhuyenMai bus = new BUS_KhuyenMai();
            DTO_KhuyenMai km = new DTO_KhuyenMai();

            km = bus.GetTinKM(MaKM);

            makm = km.MaKM;  //Ma KM
            DropDownList2.SelectedIndex = km.LoaiKM - 1 ;
            TextBox3.Text = km.TenKM.ToString();   //Tên KM
            TextBox4.Text = km.DonGiaCu.ToString();   //Đơn giá cũ
            TextBox5.Text = km.DonGiaMoi.ToString();   //Đơn giá mới
            TextBox6.Text = km.BatDauKM.ToString();
            TextBox7.Text = km.KetThucKM.ToString();
            TextBox8.Text = km.MoTa;
            TextBox9.Text = km.DiemNoiBat;
            TextBox10.Text = km.DKSuDung;
            TextBox11.Text = km.GioiThieuChiTiet;
            int Ten = km.DoanhNghiep;
            switch (Ten)
            {
                case 1: Label20.Text = "Kotex";
                    break;
                case 2: Label20.Text = "Du Lịch Việt";
                    break;
                case 3: Label20.Text = "VinaGame";
                    break;
                case 4: Label20.Text = "Gucci";
                    break;
                case 5: Label20.Text = "Bioré";
                    break;
                case 6: Label20.Text = "Apple";
                    break;
                case 7: Label20.Text = "Ngọc Lan";
                    break;
                case 8: Label20.Text = "Phú Hưng Pro";
                    break;
                case 9: Label20.Text = "Teach Good";
                    break;

            }
            TextBox13.Text = km.HinhAnh;   //Link hình ảnh
            //TextBox14.Text = km.ClipQuangCao; //Clip QC
            ddlHinhThucGiao0.SelectedIndex = km.HinhThucGiaoSP;

            DropDownList1.SelectedIndex = km.TinhTrang;
        }

        protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
        {
            BUS_KhuyenMai bkm = new BUS_KhuyenMai();
            DTO_KhuyenMai km = new DTO_KhuyenMai();
            km.MaKM = makm;
            km.LoaiKM = DropDownList2.SelectedIndex + 1;   //Loai KM
            km.TenKM = TextBox3.Text;   //Tên KM
            km.DonGiaCu = int.Parse(TextBox4.Text);   //Đơn giá cũ
            km.DonGiaMoi = int.Parse(TextBox5.Text);   //Đơn giá mới
            km.BatDauKM = DateTime.Parse(TextBox6.Text);
            km.KetThucKM = DateTime.Parse(TextBox7.Text);
            km.MoTa = TextBox8.Text;
            km.DiemNoiBat = TextBox9.Text;
            km.DKSuDung = TextBox10.Text ;
            km.GioiThieuChiTiet = TextBox11.Text;
            //km.DoanhNghiep = int.Parse(TextBox12.Text);
            km.HinhAnh = TextBox13.Text;   //Link hình ản
            //km.ClipQuangCao = TextBox14.Text; //Clip QC
            km.HinhThucGiaoSP = ddlHinhThucGiao0.SelectedIndex;
            km.TinhTrang = DropDownList1.SelectedIndex;
            bool b = bkm.UpdateTinKM(km);
            if(b == true)
            {
                string url = "~/Account_Admin/QuanLyTinKM/QuanLiTinKM.aspx";
                Response.Redirect(url);
            }
        }

    }
}